﻿/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2018. All rights reserved.
 * Description:
 * Author: 辛爱国 x30005137
 * Create: 2020-07-28
 * Notes: 无
 */
#pragma once
#include <QMouseEvent>
#include <QPropertyAnimation>
#include <QTimer>
#include <QResizeEvent>
#include <qscreen.h>
#include "errortoast.h"
#include "ui_toastdialog.h"
#include "HWDialog.h"
enum IDEASHAREKEY_TOAST_STATUS {
    TOAST_CONNECTING = 0,                   /* 连接中 */
    TOAST_HIDE = 1,                         /* 隐藏 */
    TOAST_FAIL = 2,                         /* 连接失败 */
    TOAST_DISCONNECT = 3,                   /* 断开连接 */
    TOAST_MAX = 4,                          /* 连接超过 */
    TOAST_UPGRADE = 5,                      /* 升级 */
    TOAST_DISCONNECT_AND_EXIT = 6,          /* 断开连接并退出 */
    TOAST_TIMEOUT                           /* 连接超时 */
};
class ToastDialog : public HWDialog, public Ui::ToastDialog {
    Q_OBJECT

public:
    ToastDialog(QWidget *parent = Q_NULLPTR);
    ~ToastDialog();
    void resizeEvent(QResizeEvent *event);
    void start_retry_timer();
    void stop_retry_timer();
    void start_timeout_timer();
    void stop_timeout_timer();
    void start_sharing_timeout_timer();
    void stop_sharing_timeout_timer();

    void handleConnect();
    void handleConnectBusy();
    void handleConnectRetryMax();
    void handleConnectSuccess();
    void handleConnectFailed();
    void handleDisConnectAndRetry();
    void handleDisConnectAndExit();
    void hideDisappearing(int ms);
    void closeDisappearing(int ms);

    void showConnecting();                  
    void showConnectBusy();
    void showConnectSuccess();
    void showConnectFiled();
    void showDisConnect();
    void showSharing();
    void showShareSuccess();
    void showShareStop();
    void showShareFiled(IDEASHARE_ERROR_ID &toast);
public slots:
    void handleConnectTimeout();
    void handleSharingTimeout();
    void handleConnectRetry();
    void handleKeepAlive();
    void windowReturn();
    void on_pushButtonExit_clicked();
    void updateWait();
private:
    
    void setBaseInfo(bool isshare);
    bool m_isQuit { false };
    QTimer *m_wait { nullptr };
    QTimer *m_keepalive_timer { nullptr };
    QTimer *m_retry_timer { nullptr };
    QTimer *m_timeout_timer { nullptr };
    QTimer *m_sharing_timeout_timer { nullptr };
    QPropertyAnimation *m_animation { nullptr };
    int m_spinIndex { 0 };
    int m_errorCount { 0 };
};

